﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OneMake.Model
{
    //库存分析
    public class report_kc_stat
    {
        [MapToField(FieldName = "品类")]
        public string catelog { get; set; }

        [MapToField(FieldName = "库存量")]
        public int store_num { get; set; }

        [MapToField(FieldName = "库存金额")]
        public int store_amount { get; set; }

        [MapToField(FieldName = "库存金额2")]
        public double store_amount_rate { get; set; }
    }

    public class report_kc_stat2
    {
        [MapToField(FieldName = "季节")]
        public string season { get; set; }

        [MapToField(FieldName = "库存量")]
        public int store_num { get; set; }

        [MapToField(FieldName = "库存金额")]
        public int store_amount { get; set; }

        [MapToField(FieldName = "库存金额2")]
        public double store_amount_rate { get; set; }
    }

    public class report_kc_stat3
    {
        [MapToField(FieldName = "年份")]
        public string year { get; set; }

        [MapToField(FieldName = "库存量")]
        public int store_num { get; set; }

        [MapToField(FieldName = "库存金额")]
        public int store_amount { get; set; }

        [MapToField(FieldName = "库存金额2")]
        public double store_amount_rate { get; set; }
    }

    public class report_kc_stat4
    {
        [MapToField(FieldName = "吊牌价位段")]
        public string label_price_period { get; set; }

        [MapToField(FieldName = "库存量")]
        public int store_num { get; set; }

        [MapToField(FieldName = "库存金额")]
        public int store_amount { get; set; }

        [MapToField(FieldName = "库存金额2")]
        public double store_amount_rate { get; set; }
    }

    public class report_kc_stat5
    {
        [MapToField(FieldName = "库存深度")]
        public string store_deep { get; set; }

        [MapToField(FieldName = "0-50")]
        public int period1 { get; set; }

        [MapToField(FieldName = "0以下")]
        public int period2 { get; set; }

        [MapToField(FieldName = "100-300")]
        public int period3 { get; set; }

        [MapToField(FieldName = "2000-3000")]
        public int period4 { get; set; }

        [MapToField(FieldName = "3000-4000")]
        public int period5 { get; set; }

        [MapToField(FieldName = "300-500")]
        public int period6 { get; set; }

        [MapToField(FieldName = "500-1000")]
        public int period7 { get; set; }

        [MapToField(FieldName = "50-100")]
        public int period8 { get; set; }

        [MapToField(FieldName = "1000-1500")]
        public int period9 { get; set; }

        [MapToField(FieldName = "总计")]
        public int period10 { get; set; }
    }

    partial class ReportHelper
    {
        //按品类统计
        string[] ku_type = { "牛仔裤", "西裤", "休闲裤" };
        string[] shipin_type = { "皮带", "钱包", "袜子" };
        string[] yi_type = { "背心", "长袖T恤", "长袖衬衫", "短袖T恤", "短袖衬衫", "风衣", "棉服", "皮装", "茄克", "西装", "羊毛衣", "羽绒服" };
        IList<report_kc_stat> get_report_kc_stat(int shopId, int shopid, DateTime beginTime, DateTime endTime)
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = @"select '{0}' as catelog,n_store as store_num, n_store * price as store_amount, price as store_amount_rate
                from PPF_D_JOEONE_STORE 
                where shopid={1} and (stat_datetime between {2} and {3}) and prd_name like '%{4}%' ";

            IList<report_kc_stat> items = new List<report_kc_stat>();
            foreach (string t in ku_type)
            {
                report_kc_stat item = db.SafeExecuteScalar<report_kc_stat>(string.Format(sql, t, shopid, beginTime, endTime, t));
                items.Add(item);
            }
            foreach (string t in shipin_type)
            {
                report_kc_stat item = db.SafeExecuteScalar<report_kc_stat>(string.Format(sql, t, shopid, beginTime, endTime, t));
                items.Add(item);
            }
            foreach (string t in yi_type)
            {
                report_kc_stat item = db.SafeExecuteScalar<report_kc_stat>(string.Format(sql, t, shopid, beginTime, endTime, t));
                items.Add(item);
            }
            return items;
        }
        //按季节款统计
        string[] season_type = { "春季", "春夏季", "冬季", "秋冬季", "秋季", "未定义", "夏季" };
        IList<report_kc_stat2> get_report_kc_stat2(int shopId, int shopid, DateTime beginTime, DateTime endTime)
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = @"select '{0}' as season,n_store as store_num, n_store * price as store_amount, price as store_amount_rate
                from PPF_D_JOEONE_STORE 
                where shopid={1} and (stat_datetime between {2} and {3}) and prd_name like '%{4}%' ";

            IList<report_kc_stat2> items = new List<report_kc_stat2>();
            foreach (string t in season_type)
            {
                report_kc_stat2 item = db.SafeExecuteScalar<report_kc_stat2>(string.Format(sql, t, shopid, beginTime, endTime, t));
                items.Add(item);
            }
            return items;
        }
        //按年份统计
        IList<report_kc_stat3> get_report_kc_stat3(int shopId, int shopid, DateTime beginTime, DateTime endTime)
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = @"select '{0}' as year,n_store as store_num, n_store * price as store_amount, price as store_amount_rate
                from PPF_D_JOEONE_STORE 
                where shopid={1} and (stat_datetime between {2} and {3}) and prd_name like '%{4}%' ";

            IList<report_kc_stat3> items = new List<report_kc_stat3>();
            foreach (string t in season_type)
            {
                report_kc_stat3 item = db.SafeExecuteScalar<report_kc_stat3>(string.Format(sql, t, shopid, beginTime, endTime, t));
                items.Add(item);
            }
            return items;
        }
        //按吊牌价格段统计
        string[] price_type = { "0-100", "100-200", "200-300", "300-400", "400-500", "500-1000", "1000-1500", "1500-2000", "2000以上" };
        IList<report_kc_stat4> get_report_kc_stat4(int shopId, int shopid, DateTime beginTime, DateTime endTime)
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = @"select '{0}' as label_price_period,n_store as store_num, n_store * price as store_amount, price as store_amount_rate
                from PPF_D_JOEONE_STORE 
                where shopid={1} and (stat_datetime between {2} and {3}) and prd_name like '%{4}%' ";

            IList<report_kc_stat4> items = new List<report_kc_stat4>();
            foreach (string t in price_type)
            {
                report_kc_stat4 item = db.SafeExecuteScalar<report_kc_stat4>(string.Format(sql, t, shopid, beginTime, endTime, t));
                items.Add(item);
            }
            return items;
        }
        //深度统计
        IList<report_kc_stat5> get_report_kc_stat5(int shopId, int shopid, DateTime beginTime, DateTime endTime)
        {
            var db = new PetaPoco.Database("mysql" + UserSession.Network);
            string sql = @"select '{0}' as store_deep,n_store as store_num, n_store * price as store_amount, price as store_amount_rate
                from PPF_D_JOEONE_STORE 
                where shopid={1} and (stat_datetime between {2} and {3}) and prd_name like '%{4}%' ";

            IList<report_kc_stat5> items = new List<report_kc_stat5>();
            foreach (string t in price_type)
            {
                report_kc_stat5 item = db.SafeExecuteScalar<report_kc_stat5>(string.Format(sql, t, shopid, beginTime, endTime, t));
                items.Add(item);
            }
            return items;
        }
        //尺码统计
    }
}
